package com.ll.gulimall.serach.controller;

import com.ll.gulimall.serach.service.MallSearchSearch;
import com.ll.gulimall.serach.vo.SearchParam;
import com.ll.gulimall.serach.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {


    @Autowired
    MallSearchSearch mallSearchSearch;

    /**
     * @param param 将页面的请求参数封装成整个对象
     * @return
     */
    @GetMapping("/list.html")
    public String getList(SearchParam param, Model model, HttpServletRequest request) {
        param.setQueryString(request.getQueryString());
        SearchResult result = mallSearchSearch.search(param);
        model.addAttribute("result", result);
        return "list";
    }
}
